;--------------------------------------------------------
; File Created by SDCC : free open source ANSI-C Compiler
; Version 3.7.1 #0 (MSVC)
;--------------------------------------------------------
; NY8A port
;--------------------------------------------------------
	.file	"components\soft_cap_sensor\cap_sensor.c"
	list	p=NY8B062E,c=on
	#include "ny8b062e.inc"
	.debuginfo language C89
;--------------------------------------------------------
; external declarations
;--------------------------------------------------------
	extern	_sinf
	extern	_cosf
	extern	_tanf
	extern	_cotf
	extern	_asinf
	extern	_acosf
	extern	_atanf
	extern	_atan2f
	extern	_sinhf
	extern	_coshf
	extern	_tanhf
	extern	_expf
	extern	_logf
	extern	_log10f
	extern	_powf
	extern	_sqrtf
	extern	_fabsf
	extern	_frexpf
	extern	_ldexpf
	extern	_ceilf
	extern	_floorf
	extern	_modff
	extern	_isnan
	extern	_isinf
	extern	_multi_16b
	extern	_read_14bit_rom
	extern	_Adc_Start
	extern	_Adc_SetVref
	extern	_Adc_GetOnce
	extern	_Mcu_Delayus
	extern	_Mcu_Delayms
	extern	_TouchKey_Init
	extern	_TouchKey_Scan
	extern	_Btn_Loop
	extern	_Btn_Init
	extern	_SoftCT_EvIOInt
	extern	_SoftCT_EvTimeout
	extern	_SoftCT_GetEvent
	extern	_SoftCT_Run
	extern	_SoftCT_Stop
	extern	_PORTAbits
	extern	_PORTBbits
	extern	_PCONbits
	extern	_BWUCONbits
	extern	_ABPLCONbits
	extern	_BPHCONbits
	extern	_INTEbits
	extern	_INTFbits
	extern	_ADMDbits
	extern	_ADRbits
	extern	_ADVREFHbits
	extern	_ADCRbits
	extern	_AWUCONbits
	extern	_PACONbits
	extern	_ADJMDbits
	extern	_INTEDGbits
	extern	_ANAENbits
	extern	_RFCbits
	extern	_INTE2bits
	extern	__Adc_mDiscard
	extern	__Polsys_mTicked
	extern	_TouchKey_mKeyStatus
	extern	__Btn_mIsDown
	extern	_SoftCT_mCaptureValue
	extern	_INDF
	extern	_TMR0
	extern	_PCL
	extern	_STATUS
	extern	_FSR
	extern	_PORTA
	extern	_PORTB
	extern	_PCON
	extern	_BWUCON
	extern	_PCHBUF
	extern	_ABPLCON
	extern	_BPHCON
	extern	_INTE
	extern	_INTF
	extern	_ADMD
	extern	_ADR
	extern	_ADD
	extern	_ADVREFH
	extern	_ADCR
	extern	_AWUCON
	extern	_PACON
	extern	_ADJMD
	extern	_INTEDG
	extern	_TMRH
	extern	_ANAEN
	extern	_RFC
	extern	_TM3RH
	extern	_INTE2
	extern	_TMR1
	extern	_T1CR1
	extern	_T1CR2
	extern	_PWM1DUTY
	extern	_PS1CV
	extern	_BZ1CR
	extern	_IRCR
	extern	_TBHP
	extern	_TBHD
	extern	_TMR2
	extern	_T2CR1
	extern	_T2CR2
	extern	_PWM2DUTY
	extern	_PS2CV
	extern	_BZ2CR
	extern	_OSCCR
	extern	_TMR3
	extern	_T3CR1
	extern	_T3CR2
	extern	_PWM3DUTY
	extern	_PS3CV
	extern	_BZ3CR
	extern	_P4CR1
	extern	_PWM4DUTY
	extern	_IOSTA
	extern	_IOSTB
	extern	_APHCON
	extern	_PS0CV
	extern	_BODCON
	extern	_CMPCR
	extern	_PCON1
	extern	_T0MD

	extern PSAVE
	extern SSAVE
	extern WSAVE
	extern STK04
	extern STK03
	extern STK02
	extern STK01
	extern STK00
;--------------------------------------------------------
; global declarations
;--------------------------------------------------------
	extern	_CapSS_GetValue
	extern	_CapSS_Init

;--------------------------------------------------------
; global definitions
;--------------------------------------------------------
;--------------------------------------------------------
; absolute symbol definitions
;--------------------------------------------------------
;--------------------------------------------------------
; compiler-defined variables
;--------------------------------------------------------
.segment "uninit"
r0x1001:
	.res	1
.segment "uninit"
r0x1002:
	.res	1
.segment "uninit"
r0x1003:
	.res	1
.segment "uninit"
r0x1006:
	.res	1
;--------------------------------------------------------
; initialized data
;--------------------------------------------------------
;--------------------------------------------------------
; overlayable items in internal ram 
;--------------------------------------------------------
;	udata_ovr
;--------------------------------------------------------
; code
;--------------------------------------------------------
;***
;  pBlock Stats: dbName = C
;***
;has an exit
;functions called:
;   _SoftCT_Stop
;   _SoftCT_Run
;   _SoftCT_GetEvent
;   _SoftCT_GetEvent
;   _SoftCT_Stop
;   _SoftCT_GetEvent
;   _SoftCT_Stop
;   _SoftCT_Run
;   _SoftCT_GetEvent
;   _SoftCT_GetEvent
;   _SoftCT_Stop
;   _SoftCT_GetEvent
;   _SoftCT_Stop
;   _SoftCT_Run
;   _SoftCT_GetEvent
;   _SoftCT_GetEvent
;   _SoftCT_Stop
;   _SoftCT_GetEvent
;   _SoftCT_Stop
;   _SoftCT_Run
;   _SoftCT_GetEvent
;   _SoftCT_GetEvent
;   _SoftCT_Stop
;   _SoftCT_GetEvent
;7 compiler assigned registers:
;   r0x1001
;   r0x1002
;   r0x1003
;   r0x1004
;   r0x1005
;   r0x1006
;   STK00
;; Starting pCode block
.segment "code"; module=cap_sensor, function=_CapSS_GetValue
	.debuginfo subprogram _CapSS_GetValue
;local variable name mapping:
	.debuginfo variable _mNowValue[0]=r0x1001,enc=unsigned
	.debuginfo variable _mNowValue[1]=r0x1002,enc=unsigned
_CapSS_GetValue:
; 2 exit points
	.line	81, "components\soft_cap_sensor\cap_sensor.c"; 	_CapSS_DisableInt();
	MOVIA	0x4c
	MOVAR	_INTE
	BANKSEL	_ADR
	BCR	_ADR,6
	.line	83, "components\soft_cap_sensor\cap_sensor.c"; 	_CapSS_VloadOutHigh();      // VLOAD输出高电平
	BANKSEL	_PORTA
	BSR	_PORTA,0
	.line	88, "components\soft_cap_sensor\cap_sensor.c"; 	_CapSS_CH0OutLow();    // 把电放完（低电平）
	BANKSEL	_PORTB
	BCR	_PORTB,0
	IOSTR	_IOSTB
	BANKSEL	r0x1001
	MOVAR	r0x1001
	BCR	r0x1001,0
	MOVR	r0x1001,W
	IOST	_IOSTB
	.line	89, "components\soft_cap_sensor\cap_sensor.c"; 	_CapSS_CaptureReady(); // 准备捕获计数
	MCALL	_SoftCT_Stop
	.line	90, "components\soft_cap_sensor\cap_sensor.c"; 	_CapSS_CH0StartREC();  // 开始捕获计数
	MCALL	_SoftCT_Run
	.line	91, "components\soft_cap_sensor\cap_sensor.c"; 	_CapSS_CH0InHZ();      // 开始充电
	IOSTR	_IOSTB
	BANKSEL	r0x1001
	MOVAR	r0x1001
	BSR	r0x1001,0
	MOVR	r0x1001,W
	IOST	_IOSTB
_00111_DS_:
	.line	92, "components\soft_cap_sensor\cap_sensor.c"; 	while (_CapSS_CH0GetCaptureFlag() == false)
	MCALL	_SoftCT_GetEvent
	BANKSEL	r0x1001
	MOVAR	r0x1001
	XORIA	0x01
	BTRSC	STATUS,2
	MGOTO	_00113_DS_
	.line	94, "components\soft_cap_sensor\cap_sensor.c"; 	if (_CapSS_CaptureIsOverflow())
	MCALL	_SoftCT_GetEvent
	BANKSEL	r0x1001
	MOVAR	r0x1001
	XORIA	0x02
	BTRSS	STATUS,2
	MGOTO	_00111_DS_
_00113_DS_:
	.line	97, "components\soft_cap_sensor\cap_sensor.c"; 	_CapSS_CH0StopCapture(); //停止捕获计数
	MCALL	_SoftCT_Stop
	.line	104, "components\soft_cap_sensor\cap_sensor.c"; 	if (_CapSS_CaptureIsOverflow())
	MCALL	_SoftCT_GetEvent
	BANKSEL	r0x1001
	MOVAR	r0x1001
	XORIA	0x02
	BTRSS	STATUS,2
	MGOTO	_00115_DS_
	.line	105, "components\soft_cap_sensor\cap_sensor.c"; 	mNowValue = _CAPSS_MAX_TIME * 2;
	MOVIA	0xfe
	MOVAR	r0x1001
	MOVIA	0x01
	BANKSEL	r0x1002
	MOVAR	r0x1002
	MGOTO	_00116_DS_
_00115_DS_:
	.line	107, "components\soft_cap_sensor\cap_sensor.c"; 	mNowValue = _CapSS_CH0GetCaptureValue(); //读取捕获值
	BANKSEL	_SoftCT_mCaptureValue
	MOVR	_SoftCT_mCaptureValue,W
	BANKSEL	r0x1001
	MOVAR	r0x1001
	BANKSEL	r0x1002
	CLRR	r0x1002
_00116_DS_:
	.line	189, "components\soft_cap_sensor\cap_sensor.c"; 	_CapSS_VloadOutLow();
	BANKSEL	_PORTA
	BCR	_PORTA,0
	.line	194, "components\soft_cap_sensor\cap_sensor.c"; 	_CapSS_CH0OutHigh();   //充满电（高电平）
	BANKSEL	_PORTB
	BSR	_PORTB,0
	IOSTR	_IOSTB
	BANKSEL	r0x1003
	MOVAR	r0x1003
	BCR	r0x1003,0
	MOVR	r0x1003,W
	IOST	_IOSTB
	.line	195, "components\soft_cap_sensor\cap_sensor.c"; 	_CapSS_CaptureReady(); //准备捕获计数
	MCALL	_SoftCT_Stop
	.line	196, "components\soft_cap_sensor\cap_sensor.c"; 	_CapSS_CH0StartFEC();  //开始捕获计数
	MCALL	_SoftCT_Run
	.line	197, "components\soft_cap_sensor\cap_sensor.c"; 	_CapSS_CH0InHZ();      //开始放电
	IOSTR	_IOSTB
	BANKSEL	r0x1003
	MOVAR	r0x1003
	BSR	r0x1003,0
	MOVR	r0x1003,W
	IOST	_IOSTB
_00119_DS_:
	.line	198, "components\soft_cap_sensor\cap_sensor.c"; 	while (_CapSS_CH0GetCaptureFlag() == false)
	MCALL	_SoftCT_GetEvent
	BANKSEL	r0x1003
	MOVAR	r0x1003
	XORIA	0x01
	BTRSC	STATUS,2
	MGOTO	_00121_DS_
	.line	200, "components\soft_cap_sensor\cap_sensor.c"; 	if (_CapSS_CaptureIsOverflow())
	MCALL	_SoftCT_GetEvent
	BANKSEL	r0x1003
	MOVAR	r0x1003
	XORIA	0x02
	BTRSS	STATUS,2
	MGOTO	_00119_DS_
_00121_DS_:
	.line	203, "components\soft_cap_sensor\cap_sensor.c"; 	_CapSS_CH0StopCapture(); //停止捕获计数
	MCALL	_SoftCT_Stop
	.line	210, "components\soft_cap_sensor\cap_sensor.c"; 	if (_CapSS_CaptureIsOverflow() || mNowValue == _CAPSS_MAX_TIME * 2)
	MCALL	_SoftCT_GetEvent
	BANKSEL	r0x1003
	MOVAR	r0x1003
	XORIA	0x02
	BTRSC	STATUS,2
	MGOTO	_00122_DS_
	BANKSEL	r0x1001
	MOVR	r0x1001,W
	XORIA	0xfe
	BTRSS	STATUS,2
	MGOTO	_00123_DS_
	BANKSEL	r0x1002
	MOVR	r0x1002,W
	XORIA	0x01
	BTRSS	STATUS,2
	MGOTO	_00123_DS_
_00122_DS_:
	.line	211, "components\soft_cap_sensor\cap_sensor.c"; 	mNowValue = _CAPSS_MAX_TIME * 2;
	MOVIA	0xfe
	BANKSEL	r0x1001
	MOVAR	r0x1001
	MOVIA	0x01
	BANKSEL	r0x1002
	MOVAR	r0x1002
	MGOTO	_00001_DS_
_00123_DS_:
	.line	213, "components\soft_cap_sensor\cap_sensor.c"; 	mNowValue += _CapSS_CH0GetCaptureValue(); //读取捕获值
	BANKSEL	_SoftCT_mCaptureValue
	MOVR	_SoftCT_mCaptureValue,W
	BANKSEL	r0x1003
	MOVAR	r0x1003
;;1	CLRR	r0x1004
;;101	MOVR	r0x1003,W
;;99	MOVAR	r0x1005
	MOVIA	0x00
	BANKSEL	r0x1006
	MOVAR	r0x1006
;;100	MOVR	r0x1005,W
	BANKSEL	r0x1003
	MOVR	r0x1003,W
	BANKSEL	r0x1001
	ADDAR	r0x1001,F
	BANKSEL	r0x1006
	MOVR	r0x1006,W
	BTRSC	STATUS,0
	INCR	r0x1006,W
	BTRSC	STATUS,2
	MGOTO	_00001_DS_
	BANKSEL	r0x1002
	ADDAR	r0x1002,F
_00001_DS_:
	.line	294, "components\soft_cap_sensor\cap_sensor.c"; 	_CapSS_EnableInt(); //开启中断
	MOVIA	0x41
	MOVAR	_INTE
	BANKSEL	_ADR
	BSR	_ADR,6
	.line	302, "components\soft_cap_sensor\cap_sensor.c"; 	return mNowValue;
	BANKSEL	r0x1001
	MOVR	r0x1001,W
	MOVAR	STK00
	BANKSEL	r0x1002
	MOVR	r0x1002,W
	.line	304, "components\soft_cap_sensor\cap_sensor.c"; 	}
	RETURN	
; exit point of _CapSS_GetValue

;***
;  pBlock Stats: dbName = C
;***
;has an exit
;; Starting pCode block
.segment "code"; module=cap_sensor, function=_CapSS_Init
	.debuginfo subprogram _CapSS_Init
_CapSS_Init:
; 2 exit points
	.line	30, "components\soft_cap_sensor\cap_sensor.c"; 	_CapSS_CaptureInit();
	CLRR	_TMRH
	MOVIA	0xff
	SFUN	_TMR1
	CLRA	
	SFUN	_PWM1DUTY
	MOVIA	0x08
	SFUN	_T1CR2
	MOVIA	0x02
	SFUN	_T1CR1
	.line	41, "components\soft_cap_sensor\cap_sensor.c"; 	}
	RETURN	
; exit point of _CapSS_Init


;	code size estimation:
;	  113+   33 =   146 instructions (  358 byte)

	end
